package com.talkingdata.hadoop.guard.mapper;

import com.talkingdata.hadoop.guard.bean.YarnClusterState;
import org.apache.ibatis.annotations.*;

@Mapper

public interface YarnClusterMapper {
    @Insert("insert into yarn_cluster_state (" +
            "cluster_id,apps_submitted,apps_completed," +
            "apps_failed,available_mb,available_byte_desc,allocated_mb,allocated_byte_desc,total_mb,total_byte_desc," +
            "total_virtual_cores,total_nodes,lost_nodes,unhealthy_nodes," +
            "decommissioning_nodes,decommissioned_nodes," +
            "active_nodes,shutdown_nodes,version,timestamp) values (#{clusterId}," +
            "#{appsSubmitted},#{appsCompleted},#{appsFailed},#{availableMb},#{availableByteDesc}," +
            "#{allocatedMb},#{allocatedByteDesc},#{totalMb},#{totalByteDesc},#{totalVirtualCores},#{totalNodes}," +
            "#{lostNodes},#{unhealthyNodes},#{decommissioningNodes}," +
            "#{decommissionedNodes},#{activeNodes},#{shutdownNodes},#{version},#{timestamp})")
    int insertYarnCluster(YarnClusterState yarnClusterState);
    @Select("select * from yarn_cluster_state " +
            "where cluster_id = #{cluster_id} order by id DESC limit 1 ")
    @Results({
            @Result(property = "clusterId",column = "cluster_id"),
            @Result(property = "appsSubmitted",column = "apps_submitted"),
            @Result(property = "appsCompleted",column = "apps_completed"),
            @Result(property = "appsFailed",column = "apps_failed"),
            @Result(property = "availableMb",column = "available_mb"),
            @Result(property = "availableByteDesc",column = "available_byte_desc"),
            @Result(property = "allocatedMb",column = "allocated_mb"),
            @Result(property = "allocatedByteDesc",column = "allocated_byte_desc"),
            @Result(property = "totalMb",column = "total_mb"),
            @Result(property = "totalByteDesc",column = "total_byte_desc"),
            @Result(property = "totalVirtualCores",column = "total_virtual_cores"),
            @Result(property = "totalNodes",column = "total_nodes"),
            @Result(property = "lostNodes",column = "lost_nodes"),
            @Result(property = "unhealthyNodes",column = "unhealthy_nodes"),
            @Result(property = "decommissioningNodes",column = "decommissioning_nodes"),
            @Result(property = "decommissionedNodes",column = "decommissioned_nodes"),
            @Result(property = "activeNodes",column = "active_nodes"),
            @Result(property = "shutdownNodes",column = "shutdown_nodes")
    })
    YarnClusterState selectYarnClusterStateByid(String cluster_id);
}
